package com.yanqu.road.dao.impl.activity.suoyao;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.suoyao.config.SuoYaoBookConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SuoYaoBookConfigDaoImpl extends TempDao {

    public static String getSuoYaoBookConfigSql = "select * from t_s_activity_suoyao_book where activityId=?";

    public List<SuoYaoBookConfig> getSuoYaoBookConfigList(int activityId) {
        List<SuoYaoBookConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSuoYaoBookConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SuoYaoBookConfig suoYaoBookConfig = new SuoYaoBookConfig();
                suoYaoBookConfig.setActivityId(rs.getInt("activityId"));
                suoYaoBookConfig.setBookId(rs.getInt("bookId"));
                suoYaoBookConfig.setName(rs.getString("name"));
                suoYaoBookConfig.setDesc(rs.getString("desc"));
                suoYaoBookConfig.setProbability(rs.getInt("probability"));
                suoYaoBookConfig.setReward(rs.getString("reward"));
                suoYaoBookConfig.setIsHide(rs.getInt("isHide"));
                suoYaoBookConfig.setSort(rs.getInt("sort"));
                list.add(suoYaoBookConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
